#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, d;
		cin >> n >> d;
		string s;
		cin >> s;
		int f = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] - '0' >= d)
				cout << s[i];
			else
			{
				cout << d;
				f = 1;
				for (int j = i; j < n; j++)
				{
					cout << s[j];
				}
			}
			if (f == 1)
				break;
		}
		if (f == 0)
			cout << d;
		cout << endl;
	}
	return 0;
}